package com.evildog.workspace.life.application.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.dependencies.mybatis.object.QueryConditionDTO;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.life.application.bo.AlbumCategoryBO;
import com.evildog.workspace.life.application.bo.AlbumCategoryListBO;
import com.evildog.workspace.life.application.bo.AlbumCategoryPageBO;
import com.evildog.workspace.life.application.convert.AlbumCategoryConvert;
import com.evildog.workspace.life.application.dto.AlbumCategoryDTO;
import com.evildog.workspace.life.application.dto.AlbumCategoryListDTO;
import com.evildog.workspace.life.application.dto.AlbumCategoryPageDTO;
import com.evildog.workspace.life.application.entity.AlbumCategory;
import com.evildog.workspace.life.application.entity.AlbumCategoryListDO;
import com.evildog.workspace.life.application.entity.AlbumCategoryPageDO;
import com.evildog.workspace.life.application.mapper.AlbumCategoryMapper;
import com.evildog.workspace.life.application.service.AlbumCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Service
public class AlbumCategoryServiceImpl extends ServiceImpl<AlbumCategoryMapper, AlbumCategory> implements AlbumCategoryService {

    @Override
    public PagedResult<AlbumCategoryPageBO> getPageList(PageQuery query, List<QueryConditionDTO> queryConditions, AlbumCategoryPageDTO pageDTO) {
        IPage<AlbumCategoryPageDO> page = this.baseMapper.getPageList(
                QueryConditionUtils.getPagination(query),
                queryConditions,
                pageDTO);
        return AlbumCategoryConvert.INSTANCE.convert(page);
    }

    @Override
    public AlbumCategoryBO getDetailById(Long id) {
        AlbumCategory albumCategory = this.getById(id);
        Assert.notNull(albumCategory, "albumCategory is null!");
        return AlbumCategoryConvert.INSTANCE.convert(albumCategory);
    }

    @Override
    public boolean save(AlbumCategoryDTO dto){
        AlbumCategory newAlbumCategory = AlbumCategoryConvert.INSTANCE.convert(dto);
        return save(newAlbumCategory);
    }

    @Override
    public boolean updateById(Long id, AlbumCategoryDTO dto){
        AlbumCategory oldAlbumCategory = getById(id);
        Assert.notNull(oldAlbumCategory, "albumCategory is null!");
        AlbumCategory newAlbumCategory = AlbumCategoryConvert.INSTANCE.convert(dto);
        newAlbumCategory.setId(id);
        return updateById(newAlbumCategory);
    }
}
